package com.mikey.tvolatile;

import java.util.concurrent.TimeUnit;

/**
 * @author :Mikey
 * @description :JMM存在问题演示
 * @create :2022-09-27 13:47:00
 */
public class JMMDemo {
    //不加volatile 程序就会死循环
    private  volatile static int num=0;
    public static void main(String[] args) {//main线程
        new Thread(()->{//此线程 对主内存的变化知道
            while (num==0){
            }
        }).start();
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        num=1;
        System.out.println(num);
    }
}
